﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication2
{
    /// <summary>
    /// WindowBinding.xaml 的交互逻辑
    /// </summary>
    public partial class WindowBinding : Window
    {
        class MyData : DependencyObject
        {
            public static readonly DependencyProperty NameProperty =
             DependencyProperty.Register("Name", typeof(string), typeof(MyData),
             new UIPropertyMetadata("Hello, World!"));

            public string Name
            {
                get { return (string)GetValue(NameProperty); }
                set { SetValue(NameProperty, value); }
            }
        }

        MyData data;
        public WindowBinding()
        {
            InitializeComponent();
            data = new MyData();
            var binding = new Binding("Name") { Source = data };
            this.textbox1.SetBinding(TextBox.TextProperty, binding);
        }

        private void buttonClick(object sender, RoutedEventArgs e)
        {
            if (sender == btnSet)
                data.Name =data+",内存修改";
            else
                MessageBox.Show(data.Name);
        }

    }
}
